package Java常用类的学习;

import java.util.*;

public class PriorityQueueTest {
    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<Integer>();
        Random rand=new Random(99);
        for(int i=0;i<10;i++){
//            将随机数字插入到队列中
            priorityQueue.offer(rand.nextInt(i+10));
        }
        QueueTest1.printQ(priorityQueue);
        List<Integer> list= Arrays.asList(20,18,16,14,12,9,6,1,1,2,6,9,14,16,18,12,20);
        priorityQueue =new PriorityQueue<Integer>(list);
        QueueTest1.printQ(priorityQueue);
//        逆序
        priorityQueue=new PriorityQueue<>(list.size(),Collections.reverseOrder());
//        向队列中加入元素
        priorityQueue.addAll(list);
        QueueTest1.printQ(priorityQueue);
        String fact="EDUCATION SHOULD ESCHEW OFBFUSCATION";
//        分裂字符串返回一个字符数组
        List<String> strings=Arrays.asList(fact.split(""));
        PriorityQueue<String> stringQ=new PriorityQueue<String>(strings);
        QueueTest1.printQ(stringQ);
//        初始化
        stringQ=new PriorityQueue<String>(strings.size(),Collections.reverseOrder());
//        添加
        stringQ.addAll(strings);
        QueueTest1.printQ(stringQ);

    }
}
class QueueTest1{
//    输出队列
    public static void printQ(Queue queue){
//        获取队列的头方法
        while(queue.peek()!=null) System.out.print(queue.remove()+" ");
        System.out.println();
    }
}
